package edu.njucm.herbiv.controller;

import edu.njucm.herbiv.pojo.entity.Chemicals;
import edu.njucm.herbiv.pojo.entity.Formula;
import edu.njucm.herbiv.pojo.entity.Proteins;
import edu.njucm.herbiv.pojo.entity.TCM;
import edu.njucm.herbiv.service.ChemicalsService;
import edu.njucm.herbiv.service.FormulaService;
import edu.njucm.herbiv.service.ProteinsService;
import edu.njucm.herbiv.service.TCMService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ZhouHang
 * @Date 24/4/26 026
 */
@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "*")
public class BaseController {
    @Resource
    private TCMService tcmService;
    @Resource
    private ProteinsService proteinsService;
    @Resource
    private FormulaService formulaService;
    @Resource
    private ChemicalsService chemicalsService;

    @GetMapping("/tcm/list")
    public Page<TCM> tcmList(
            @RequestParam(value = "type") String type,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size
    ) {
        return tcmService.list(type, content, page, size);
    }

    @GetMapping("/protein/list")
    public Page<Proteins> proteinList(
            @RequestParam(value = "type") String type,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size
    ) {
        return proteinsService.list(type, content, page, size);
    }


    @GetMapping("/chemical/list")
    public Page<Chemicals> chemicalList(
            @RequestParam(value = "type") String type,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size
    ) {
        return chemicalsService.list(type, content, page, size);
    }

    @GetMapping("/formula/list")
    public Page<Formula> formulaList(
            @RequestParam(value = "type") String type,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size
    ) {
        return formulaService.list(type, content, page, size);
    }
}
